package com.fitbet.entity.bet;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.demo2do.core.format.PersistentFormat;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fitbet.entity.user.User;
/**
 * 
 * @author sjh
 *
 */

@Entity
@Table(name = "user_bet_support")
@PersistentFormat
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class UserBetSupport {
	
	@Id
	@GeneratedValue
	private Long id;
	
	@ManyToOne(fetch = FetchType.LAZY, optional = false)
	@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
	private Bet bet;
	
	@ManyToOne(fetch = FetchType.LAZY, optional = false)
	@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
	private UserBet userBet;
	
	@ManyToOne(fetch = FetchType.LAZY, optional = false)
	@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
	private User user;
	
	private UserBetSupportStatus status;
	
	private int price;
	
	/**
	 * 小赌局赢得奖金
	 */
	private int bonus;
	
	private Date createDtae;
	
	/**
	 * 看好/不看好
	 */
	private boolean support;
	
	@Column(name = "is_disabled")
	private boolean disabled;
	
	/**
	 * The default constructor
	 */
	public UserBetSupport() {
		
	}
	
	/**
	 * 
	 * @param user
	 * @param userBet
	 * @param support
	 */
	public UserBetSupport(User user, UserBet userBet, boolean support) {
	    this.user = user;
	    this.userBet = userBet;
	    this.bet = userBet.getBet();
	    this.support = support;
	    this.status = UserBetSupportStatus.CREATED;
	    
	}
	
	/**
	 * 
	 * @param bonus
	 * @return
	 */
	public UserBetSupport bounsResult(int bonus) {
		this.bonus = bonus;
		return this;
	}
	
	/**
	 * 
	 * @return
	 */
	public UserBetSupport init() {
	    this.price = 10000;
	    this.createDtae = new Date();
	    this.disabled = false;
	    
	    return this;
	}
	
	/**
	 * 
	 * @return
	 */
	public UserBetSupport paid() {
	    this.status = UserBetSupportStatus.PAID;
	    return this;
	}
	
	public UserBetSupport finish() {
	    this.status = UserBetSupportStatus.FINISHED;
	    return this;
	}
	
	/**
     * 
     * @return
     */
    public Map<String, Object> getBets() {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("betId", this.bet.getId());
        parameters.put("betAvatar", this.bet.getAvatar());
        parameters.put("betName", this.bet.getName());
        parameters.put("betStartDate", this.bet.getStartDate());
        parameters.put("betEndDate", this.bet.getEndDate());
        parameters.put("betStatus", this.bet.getStatus());
        parameters.put("betBonus", this.bet.getBetBonus());
        parameters.put("betThumbAmount", this.bet.getThumbAmount());
        return parameters;
    }
    
    /**
     * 
     * @return
     */
    public Map<String, Object> getUserBets() {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("userBetId", this.userBet.getId());
        parameters.put("userBetBeforeVedio", this.userBet.getBeforeVedio());
        parameters.put("userBetBeforeVedioReason", this.userBet.getBeforeVedioReason());
        parameters.put("userBetAfterWeight", this.userBet.getAfterWeight());
        parameters.put("userBetAfterVedio", this.userBet.getAfterVedio());
        parameters.put("userBetAfterVedioReason", this.userBet.getAfterVedioReason());
        parameters.put("userBetCreateTime", this.userBet.getCreateTime());
        parameters.put("userBetBonus", this.userBet.getBonus());
        parameters.put("userBetStatus", this.userBet.getStatus());
        parameters.put("userBetSuccess", this.userBet.isSuccess());
        parameters.put("userBetBetResult", this.userBet.getBetResult());
        parameters.put("userBetSupportResult", this.userBet.getSupportResult());
        parameters.put("userBetThumbup", this.userBet.getThumbup());
        parameters.put("userBetThumbdown", this.userBet.getThumbdown());
        return parameters;
    }

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @return the bet
	 */
	public Bet getBet() {
		return bet;
	}

	/**
	 * @return the userBet
	 */
	public UserBet getUserBet() {
		return userBet;
	}

	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}

	/**
	 * @return the status
	 */
	public UserBetSupportStatus getStatus() {
		return status;
	}

	/**
	 * @return the price
	 */
	public int getPrice() {
		return price;
	}

	/**
	 * @return the bonus
	 */
	public int getBonus() {
		return bonus;
	}

	/**
	 * @return the createDtae
	 */
	public Date getCreateDtae() {
		return createDtae;
	}

	/**
	 * @return the support
	 */
	public boolean isSupport() {
		return support;
	}

	/**
	 * @return the disabled
	 */
	public boolean isDisabled() {
		return disabled;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param bet the bet to set
	 */
	public void setBet(Bet bet) {
		this.bet = bet;
	}

	/**
	 * @param userBet the userBet to set
	 */
	public void setUserBet(UserBet userBet) {
		this.userBet = userBet;
	}

	/**
	 * @param user the user to set
	 */
	public void setUser(User user) {
		this.user = user;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(UserBetSupportStatus status) {
		this.status = status;
	}

	/**
	 * @param price the price to set
	 */
	public void setPrice(int price) {
		this.price = price;
	}

	/**
	 * @param bonus the bonus to set
	 */
	public void setBonus(int bonus) {
		this.bonus = bonus;
	}

	/**
	 * @param createDtae the createDtae to set
	 */
	public void setCreateDtae(Date createDtae) {
		this.createDtae = createDtae;
	}

	/**
	 * @param support the support to set
	 */
	public void setSupport(boolean support) {
		this.support = support;
	}

	/**
	 * @param disabled the disabled to set
	 */
	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

}
